<template>
  <!--企业新增弹层start -->
  <el-dialog
    v-dialogDrag
    :title="dialogTitle"
    :visible.sync="dialogVisible"
    class="dialogStyleMiddle"
    :before-close="cancel"
  >
    <el-row>
      <el-form :inline="true">
        <el-form-item label="企业名称">
          <el-input
            v-model="filters.name"
            size="medium"
            class="serach-person"
            placeholder="请输入企业名称"
          />
          <el-button size="medium" type="primary" @click="searchSupplier">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-table ref="multipleTable" :data="tableData" style="width: 100%;" stripe class="table-list">
        <el-table-column prop="name" label="企业名称" min-width="150" align="center" />
        <el-table-column prop="enterpriseType" :show-overflow-tooltip="true" :formatter="formartType" label="企业类型" min-width="120" align="center" />
        <el-table-column prop="creditCodePic" label="信用代码" width="190" align="center" />
        <el-table-column label="操作" align="center" width="80">
          <template slot-scope="{row}">
            <i class="iconfont icon-tianjiagonghuoshang add-icon" @click="selectEnterprise(row)" />
          </template>
        </el-table-column>
      </el-table>
    </el-row>
  </el-dialog>
</template>

<script>
import { listEnterpriseType } from '@/api/supplier/cooperativeEnterprise'
export default {
  props: {
    typeOptions: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      // 筛选企业
      filters: {
        name: '',
        sysEnterpriseType: ''
      },
      // 企业列表
      tableData: [],
      dialogTitle: '', // 弹层标题
      dialogVisible: false // 弹层是否显示
    }
  },
  methods: {
    // 筛选人员
    searchSupplier() {
      listEnterpriseType(this.filters).then(res => {
        if (res.data) {
          this.tableData = res.data.rows
        }
      })
    },
    // 添加企业
    selectEnterprise(row) {
      this.$confirm('是否添加该企业?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      })
        .then(() => {
          // this.msgSuccess('等待对方确认！')
        })
        .catch(() => {})
    },
    /* 新增/编辑弹层 start*/
    // 新增/编辑
    handleAdd(title, sysEnterpriseType) {
      this.dialogTitle = title
      this.dialogVisible = true
      this.filters.sysEnterpriseType = sysEnterpriseType
      this.searchSupplier()
    },
    formartType(row) {
      if (JSON.stringify(row) === '{}') return
      const item = this.typeOptions.find(item => {
        return item.typeNum === row.enterpriseType
      })
      return item && item.typeName
    },
    // 取消按钮
    cancel() {
      this.dialogVisible = false
    },
    // 提交按钮
    submitForm() {
      this.msgSuccess('保存成功')
      this.cancel()
      this.$parent.getList()
    }
    /* 新增弹层 end*/
  }
}
</script>

<style scoped>
</style>
